import os
import subprocess
import shutil

def diagnose_desktop():
    """诊断桌面环境"""
    print("=== 桌面环境诊断 ===")
    print(f"XDG_CURRENT_DESKTOP: {os.environ.get('XDG_CURRENT_DESKTOP')}")
    print(f"DESKTOP_SESSION: {os.environ.get('DESKTOP_SESSION')}")
    print(f"GDMSESSION: {os.environ.get('GDMSESSION')}")
    print(f"当前用户: {os.environ.get('USER')}")
    
    # 检查常见壁纸设置工具
    tools = ['feh', 'nitrogen', 'gsettings', 'xfconf-query', 'plasma-apply-wallpaperimage']
    for tool in tools:
        path = shutil.which(tool)
        if path:
            print(f"✓ 找到 {tool}: {path}")
        else:
            print(f"✗ 未找到 {tool}")
    
    # 尝试获取当前壁纸设置
    try:
        result = subprocess.run(['gsettings', 'get', 'org.gnome.desktop.background', 'picture-uri'], 
                              capture_output=True, text=True)
        if result.returncode == 0:
            print(f"当前GNOME壁纸: {result.stdout.strip()}")
    except:
        pass

# 运行诊断
diagnose_desktop()